﻿using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using Utils.AppHelper;

namespace Extensions.Extensions
{
    /// <summary>
    /// 静态SqlSugar扩展类
    /// </summary>
    public static class SqlsugarSetup
    {
        public static SqlSugarClient db
        {
            get
            {
                return new SqlSugarClient(new ConnectionConfig()
                {
                    ConnectionString = Appsettings.GetValue("ConnectionStrings:SqlServer"),//数据库连接字符串
                    DbType = DbType.SqlServer,//DbType支持Mysql、SqlServer、Sqlite、Oracle、PostgreSQL等多种数据库
                    IsAutoCloseConnection = true,//自动释放
                });
            }
        }

        /// <summary>
        /// sqlsugar
        /// </summary>
        /// <param name="service">服务</param>
        /// <param name="configuration">配置文件</param>
        public static void AppSqlsugarSetup(this IServiceCollection service)
        {
            //单例注入
            service.AddSingleton<ISqlSugarClient>(db);
        }
    }
}
